﻿using System.Drawing;
using System.Drawing.Imaging;

namespace SnapDesktop
{
    internal class ImageSnapper
    {
        private Bitmap _bmpScreenshot;
        private Graphics _gfxScreenshot;

        public Image Snap(int x, int y, int width, int height)
        {
            _bmpScreenshot = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            _gfxScreenshot = Graphics.FromImage(_bmpScreenshot);
            _gfxScreenshot.CopyFromScreen(x, y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
            return _bmpScreenshot;
        }

        public Image Snap(Rectangle r)
        {
            _bmpScreenshot = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppPArgb);
            _gfxScreenshot = Graphics.FromImage(_bmpScreenshot);
            _gfxScreenshot.CopyFromScreen(r.X, r.Y, 0, 0, new Size(r.Width, r.Width), CopyPixelOperation.SourceCopy);
            return _bmpScreenshot;
        }
    }
}